package org.jeecg.modules.wlhy.controller;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.modules.third.aliyunocr.AliyunOcrService;
import org.jeecg.modules.wlhy.hyconfig.entity.HyConfig;
import org.jeecg.modules.wlhy.utils.HyConfigUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/hycommon")
@Slf4j
public class HyCommonController{
	@Autowired
	private AliyunOcrService aliyunOcrService;

	@PostMapping(value = "/checkBankCard")
	public Result<?> checkBankCard(@RequestBody JSONObject jsonObject) {
		String bankName = jsonObject.getString("bankName");
		if(StringUtils.isEmpty(bankName)){
			return Result.error("开户人姓名不能为空");
		}
		String bankNum = jsonObject.getString("bankNum");
		if(StringUtils.isEmpty(bankNum)){
			return Result.error("银行卡号不能为空");
		}
		String idcard = jsonObject.getString("idcard");
		if(StringUtils.isEmpty(idcard)){
			return Result.error("开户人身份证号不能为空");
		}
		HyConfig systemConfig = HyConfigUtils.getConfig();
		if (systemConfig == null || !systemConfig.getAliyunOcrIzUse()) {
			return Result.error(-1, "银行卡校验服务暂未开启,请联系管理员。");
		}
		return aliyunOcrService.ToolsBank(idcard , bankName, bankNum);
	}

}
